/*
 * @Author: wang cong wangc9832@163.com
 * @Date: 2023-06-15 09:44:03
 * @LastEditors: wang cong wangc9832@163.com
 * @LastEditTime: 2024-02-22 17:31:24
 * @FilePath: /ams_kt_front/src/api/finance/amsBillManage.ts
 * @Description:
 *
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved.
 */
import { BasicFetchResult } from '../model/baseModel';
import { defHttp } from '@/utils/http/axios';
import { downloadBlob } from '@/utils/file/download';
const api = '/amsBill';
// 应收应退单条明细查询
export const detail = (id?: any) =>
  defHttp.get<BasicFetchResult<any>>({ url: api + '/detail/' + id });

// 应退明细_删除
export const del = (ids: string[]) =>
  defHttp.post({ url: api + '/delete', params: ids });
// 应收明细导出
export const exportReceipt = (params?: any) => {
  return new Promise<void>((resolve, reject) => {
    defHttp
      .get(
        { responseType: 'blob', url: api + '/exportReceipt', params },
        { isReturnNativeResponse: true },
      )
      .then((res) => {
        downloadBlob(res);
        resolve();
      })
      .catch(() => {
        reject();
      });
  });
};
// 应退明细导出
export const exportRefund = (params?: any) => {
  return new Promise<void>((resolve, reject) => {
    defHttp
      .get(
        { responseType: 'blob', url: api + '/exportRefund', params },
        { isReturnNativeResponse: true },
      )
      .then((res) => {
        downloadBlob(res);
        resolve();
      })
      .catch(() => {
        reject();
      });
  });
};
// 查询旧账单
export const oldBill = (params?: any) =>
  defHttp.get<BasicFetchResult<any>>({ url: api + '/oldBill/', params });

// 查询应收应退开启-关闭
export const operation = (id?: any) =>
  defHttp.post({ url: api + '/operation/' + id });

//查询退租检查账单是否可关闭数据
export const check = (billCode?: any) =>
  defHttp.get<BasicFetchResult<any>>({ url: api + '/check/' + billCode });
export const tabCount = () =>
  defHttp.get<BasicFetchResult<any>>({ url: api + '/tabCount' });

// 应收应退明细_增加
export const addRefund = (params?: any) =>
  defHttp.post({ url: api + '/addRefund', params });
// 应收应退明细查询 ==》账单详情
// 合同号查询账单相关
export const contractBillDetail = (contractCode: any, params?: any) =>
  defHttp.get<BasicFetchResult<any>>({
    url: `/${api}/contractBillDetail/${contractCode}`,
    params,
  });
/**
 * 查询应收应退明细分页
 * @author frank
 * @date 2023-06-09 16:30:27
 */
export const page = (params?: any) =>
  defHttp.get<BasicFetchResult<any>>({ url: api + '/page', params });
/**
 * 添加应收应退明细
 * @author frank
 * @date 2023-06-09 16:30:27
 */
export const add = (params?: any) =>
  defHttp.post({ url: api + '/add', params });
/**
 * 修改应收应退明细
 * @author frank
 * @date 2023-06-09 16:30:27
 */
export const edit = (params?: any) =>
  defHttp.post({ url: api + '/edit', params });

// 修改应付单
export const editRefund = (params?: any) =>
  defHttp.post({ url: api + '/editRefund', params });
// 预警
export const warningPage = (params?: any) =>
  defHttp.get<BasicFetchResult<any>>({ url: api + '/warningPage', params });
